package com.atstudent.gmall.product.controller;

import com.atstudent.gmall.common.result.Result;
import com.atstudent.gmall.product.dto.SpuInfoDto;
import com.atstudent.gmall.product.service.SpuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * spu属性
 * @Author 薛有朋
 * @CreatDate 2024/11/24 21:36
 **/
@RestController
@RequestMapping(value = "/admin/product")
public class SpuInfoController {

    @Autowired
    private SpuInfoService spuInfoService;

    /**
     * 获取spu分页列表
     * @Author 薛有朋
     * @Date 2024/11/24 21:37
     **/
    @GetMapping(value = "/{page}/{limit}")
    public Result<Page> findByPage(
            @PathVariable(value = "page") Integer pageNum,
            @PathVariable(value = "limit") Integer pageSize,
            @RequestParam(value = "category3Id") Long category3Id
    ){
        Page page = spuInfoService.findByPage(pageNum , pageSize , category3Id);
        return Result.ok(page);
    }

    /**
     * 添加spu
     * @Author 薛有朋
     * @Date 2024/11/25 19:46
     **/
    @PostMapping(value = "/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfoDto spuInfoDto){
        spuInfoService.saveSpuInfo(spuInfoDto);
        return Result.ok();
    }
}
